<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        {include file="public/header"}
    </head>
    
    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <!-- <a href="">首页</a>
                <a href="">演示</a>
                <a>
                    <cite>导航元素</cite></a> -->
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <table class="layui-table" id="data-table" lay-filter="data-table">
                                
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
	<script type="text/html" id="room_state">
	    {{# if(d.room_state=='0'){ }}
	    禁用
	    {{# }else{ }}
	    正常
	    {{# } }}
	</script>
  <script type="text/html" id="url">
      <img src="{{d.url}}">
  </script>
	<script type="text/html" id="message_state">
	    {{# if(d.message_state=='0'){ }}
	    不审核
	    {{# }else{ }}
	    审核
	    {{# } }}
	</script>
	<script type="text/html" id="topBtn">
	    <button type="button" class="layui-btn  layui-btn-sm" onclick="xadmin.open('添加banner','{:url('home/addBanner')}')">添加banner</button>
	</script>
    <script type="text/html" id="barDemo">
	  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
	  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	</script>
    <script>
        layui.use(['table', 'util'], function(){
          var table = layui.table, util= layui.util;
          //第一个实例
          table.render({
            elem: '#data-table'
            ,toolbar: '#topBtn'
            ,url: '{:url('home/homeBanner')}' //数据接口
            ,cols: [[ //表头
               {field:  'id', title: 'ID'}
              ,{field: 'title', title: '标题名',}
              ,{field: 'room_id' , title: '使用房间'}
              ,{field: 'link' , title: '链接地址'}
              ,{field: 'url'  , title: '图片地址' , templet:'#url'} 
              ,{field: 'state', title: '房间状态', templet:'#room_state'}
              ,{field: 'c_time', title: '创建时间' ,templet:function(d){return util.toDateString(d.commPosttime*1000, "yyyy-MM-dd HH:mm:ss");}}
               ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
          });

          //放大图片
          $(document).on('click','img',function () {
              var src = $(this).attr('src');
              layer.open({
                type: 1,
                area: ['880px', '520px'], 
                title: false,
                content: '<img src="'+src+'" style="width:100%;height:100%">' 
              });
          })

          table.on('tool(data-table)', function(obj) {
              var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定要删除吗？', function(index){
                    $.post('{:url('home/delhome')}',{room_id:data.room_id},function(res)
                    {
                        if(res.code == 200)
                        {
                            obj.del();
                            layer.close(index);
                        }else{
                            layer.msg(res.msg);
                            return false;
                        }
                    })
                })
            }else if(obj.event === 'edit'){
                xadmin.open('编辑房间','{:url('home/editHome')}?id='+data.id)
                return false;
            }

          })
          
        });
    </script>
</html>